package edu.rit.varapp.datalayer;

import java.util.HashMap;

/**
 * Represents a Message object.
 * @author Eric Kisner
 */
public class Message {

    public static final char UNREAD = 'U';
    public static final char READ = 'R';
    private int messageId;
    private int entityId;
    private String message;
    private String date;
    private String subject;
    private char status;

    /**
     * Full constructor
     */
    public Message( int messageId, int entityId, String message, String date, String subject, char status ) {
        this.messageId = messageId;
        this.entityId = entityId;
        this.message = message;
        this.date = date;
        this.subject = subject;
        this.status = status;
    }

    public Message( int messageId, int entityId, String message, String subject ) {
        this.messageId = messageId;
        this.entityId = entityId;
        this.message = message;
        this.subject = subject;
        this.date = "NOW()";
        this.status = UNREAD;
    }

    public char getStatus() {
        return status;
    }

    public String getSubject() {
        return subject;
    }

    public String getDate() {
        return date;
    }

    public int getEntityId() {
        return entityId;
    }

    public String getMessage() {
        return message;
    }

    public int getMessageId() {
        return messageId;
    }

    @Override
    public String toString() {
        return "Message{"
               + "messageId=" + messageId
               + "\tentityId=" + entityId
               + "\tmessage=" + message
               + "\tdate=" + date
               + "\tsubject=" + subject
               + "\tstatus=" + status + '}';
    }

    public static String columnsToSQL() {
        return "MessageId, EntityId, Message, Date, Subject, Status";
    }

    public String valuesToSQL() {
        return messageId + ", " + entityId + ", '" + message + "', " + date + ", '" + subject + "', '" + status + "'";
    }

    public HashMap<String, String> asMap( boolean includeIds ) {
        HashMap<String, String> ret = new HashMap<String, String>();
        if( includeIds ) {
            ret.put( "Message Id", String.valueOf( messageId ) );
            ret.put( "Entity Id", String.valueOf( entityId ) );
        }
        ret.put( "Message", message );
        ret.put( "Date", date );
        ret.put( "Subject", subject );
        ret.put( "Status", ((status == UNREAD) ? "Unread" : "Read") );
        return ret;
    }
}
